package com.dongzili.binlog.common.binlogsynchronization;

import com.github.shyiko.mysql.binlog.BinaryLogClient;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class BinLogServer {

    private final BinaryLogClient binaryLogClient;
    private final MysqlBinLogListener mysqlBinLogListener;
//    private final RedisService<String, BinLogProgress> redisService;
//    public final static String binLogName = "binLogName";



    @SneakyThrows
    @EventListener(ApplicationReadyEvent.class)
    public void listenToBinaryLogEvent() {
        binaryLogClient.registerEventListener(mysqlBinLogListener);
//        BinLogProgress binLogProgress = redisService.getCacheObject(binLogName);
//        if (ObjectUtil.isNotNull(binLogProgress)) {
//            binaryLogClient.setBinlogFilename(binLogProgress.getBinlogFilename());
//            binaryLogClient.setBinlogPosition(binLogProgress.getBinlogPosition());
//
//        }
        binaryLogClient.connect(300);
    }


}
